<!DOCTYPE html>
<html lang="en">

<head>
    <meta charmap="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>策略模式</title>
</head>

<body>
    <script>
        // 策略模式替换if/switch语句
        const obj = {
            'S': function (salary) {
                return salary * 1.5
            },
            'A': function (salary) {
                return salary * 1.2
            },
            'B': function (salary) {
                return salary * 1
            }
        }

        function getSalary (level, salary) {
            return obj[level](salary)
        }

        getSalary('S', 10000) // 15000 
        getSalary('A', 8000) // 9600
        getSalary('B', 5000) // 5000

    </script>
</body>

</html>